﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
using System.Drawing;
using System.Text;
public partial class OrderDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {



        if (Session["name"] == null)
        {
            Response.Redirect("~/error.aspx?");
        }
        else
        {
            if (!IsPostBack)
            {
                this.bind();
            }
        }
        string JudgePower = Session["power"].ToString();
        if (JudgePower != "超级管理员" && JudgePower != "仓库管理员" && JudgePower != "销售" && JudgePower != "查询用户" && JudgePower != "工程师" && JudgePower != "主管")
        {

            Response.Redirect("~/PowerError.aspx?");
        }
    }
    public SqlConnection GetConnection()
    {
        string myStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
        SqlConnection myConn = new SqlConnection(myStr);
        return myConn;
    }

    protected void bind()
    {
        SqlConnection myConn = GetConnection();
        myConn.Open();
        string sqlStr = "select GID as 货品编号,GTYPEName as 类别,GCHName as 名称,GXinhao as 型号,GBrand as 品牌,SWID as 仓库编号,SQuantity as 现有数量,STopLine as 数量上限,GProvider1 as 主供应商,GProvider2  as 次供应商 from Goods , Store where Goods.GID=Store.SGID";
        SqlDataAdapter myDa = new SqlDataAdapter(sqlStr, myConn);
        DataSet myDs = new DataSet();
        myDa.Fill(myDs);
        GridView1.DataSource = myDs;
        // GridView1.DataKeyNames = new string[] { "ID" };
        GridView1.DataBind();
        myDa.Dispose();
        myDs.Dispose();
        myConn.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text == "")
        {
            Response.Write("<script>alert('输入不能为空!')</script>");
        }
        else
        {
            SqlConnection myConn = GetConnection();
            myConn.Open();
            string sqlStr = "select GID as 货品编号,GTYPEName as 类别,GCHName as 名称,GXinhao as 型号,GBrand as 品牌,SWID as 仓库编号,SQuantity as 现有数量,SbaseLine as 数量下限,STopLine as 数量上限,GProvider1 as 主供应商,GProvider2  as 次供应商 from Goods , Store where Goods.GID=Store.SGID  and (Goods.GXinhao like '%" + TextBox1.Text.Trim().ToString() + "%' or Goods.GCHName like '%" + TextBox1.Text.Trim().ToString() + "%')";
            SqlDataAdapter myDa = new SqlDataAdapter(sqlStr, myConn);
            DataSet myDs = new DataSet();
            myDa.Fill(myDs);
            GridView1.DataSource = myDs;
            // GridView1.DataKeyNames = new string[] { "ID" };
            GridView1.DataBind();
            myDa.Dispose();
            myDs.Dispose();
            myConn.Close();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Orderdaochu.aspx?");
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        bind();
    }
}